package com.common.controller;

import com.common.model.Result;
import com.common.model.TaskCondition;
import com.common.service.TasksService;
import com.mrobuy.jdvc.entity.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 店铺管理
 */
@RestController
public class CollectsController {

	private static Logger LOG = LoggerFactory.getLogger(CollectsController.class);

	@Autowired
	private TasksService tasksService;

	@Autowired
	private RedisTemplate<String, Object> redisTemplate;

	@RequestMapping("/common/collects")
	public Result collects(@ModelAttribute TaskCondition condition) {
		return  tasksService.loadTasks(condition);
	}

	@RequestMapping("/common/collects/buildtask")
	public Result buildtask(@ModelAttribute Task task) {
		return  tasksService.buildShelvesTask(task);
	}


	@RequestMapping("/redis/set")
	public Result redisSet(@RequestBody Map<String, Object> values) {

		System.out.println(values);

		for (String s : values.keySet()) {
			redisTemplate.opsForValue().set(s, values.get(s));
		}

		return  Result.EMPTY;
	}

	@RequestMapping("/redis/{key}")
	public Object redisGet(@PathVariable String key) {
		return redisTemplate.opsForValue().get(key);
	}


}
